package com.kmxd.ams.core.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * "元数据模板类型
 * document文书档案、account会计档案、technical科技档案、img照片档案、radio音频档案、video视频档案、entity实物档案、other其他档案、material资料
 * 这里是定义“业务附加元数据”")
 *
 * @author nickbi
 */
@Getter
@AllArgsConstructor
public enum ArchModelEnum {

  /** 文书 */
  DOCUMENT("document", "文本文件"),
  IMG("photos", "照片文件"),
  VIDEO("video", "影像文件"),
  PHYSICAL("physical", "实物文件"),
  MATERIAL("material", "资料文件");

  private String code;
  private String desc;

  public static ArchModelEnum convert(String type) {
    return Arrays.stream(values())
        .filter(x -> x.code.equals(type))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到档案状态：" + type));
  }

  @JsonCreator
  public static ArchModelEnum getValue(Integer type) {
    return Arrays.stream(values()).filter(x -> Objects.equals(x.code, type)).findAny().orElse(null);
  }
}
